package com.example.todolist.mapper;

import com.example.todolist.entity.ReviewTask;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;

@Mapper
public interface ReviewTaskMapper {
    @Select("select * from reviewTask where userId=#{userId} AND date=#{date}")
    List<ReviewTask> getOneDayTask(Integer userId, Date date);
    @Select("select count(*) from reviewTask where userId=#{userId} AND date=#{date} AND taskName=#{taskName}")
    Integer checkIfTaskExist(Integer userId, Date date,String taskName);

    @Insert("insert into reviewTask(userId,taskName,date,description,taskType) VALUES(#{userId},#{taskName},#{date},#{description},#{taskType})")
    void addReviewTask(Integer userId, String taskName, Date date,String description,String taskType);

    @Select("select count(*) from reviewTask where userId=#{userId} AND TaskDone=1 AND date=#{date}")
    Integer countTheTaskDone(Integer userId,Date date);

    @Select("select count(*) from reviewTask where userId=#{userId} AND TaskDone=0")
    Integer countTheTaskNot(Integer userId);

    @Delete("delete from reviewTask where userId=#{userId} AND date=#{date}")
    void deleteOneTask(Integer userId, Date date);
    @Select("select * from reviewTask where userId=#{userId} AND year(date)=#{year} AND month(date)=#{month}")
    List<ReviewTask> getThisMonthReviewTask(Integer userId, Integer year, Integer month);

    @Select("select taskName from reviewTask where userId=#{userId} AND date_sub(curdate(),interval 1 day) <= date AND taskDone=1")
    List<String> getLastDayReviewTask(Integer userId);

    @Select("select * from reviewTask where userId=#{userId} AND taskDone=0 AND date<#{date}")
    List<ReviewTask> getForgetReviewTask(Integer userId,Date date);

    @Update("update reviewTask set taskDone=1 where userId=#{userId} AND date=#{date} AND taskName=#{taskName}")
    void checkForTask(Integer userId, Date date,String taskName);

    @Select("select * from reviewTask where userId=#{userId}")
    List<ReviewTask> getAllReviewTask(Integer userId);

    @Select("select * from reviewTask where userId=#{userId} AND date=#{date} AND taskName=#{taskName}")
    ReviewTask getOneReviewTask(Integer userId,Date date,String taskName);

    @Update("update reviewTask set taskDone=0 where userId=#{userId} AND date=#{date} AND taskName=#{taskName}")
    void resetForTask(Integer userId, Date date, String taskName);
}
